<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/inc/taglib.jsp" %>
<%-- 设置URL参数 --%>
<c:set var="queryURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}" />
<c:set var="createURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/create" />
<c:set var="updateURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/${r'${model.' }${primaryKeyColumns[0].javaProperty }${r'}' }/update" />
<c:set var="editURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/create||${baseURL}/${domainObjectName?uncap_first}/${r'${model.' }${primaryKeyColumns[0].javaProperty }${r'}' }/update" />
<%-- 权限设置 --%>
<c:set var="createPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:create" />
<c:set var="updatePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:update" />
<c:set var="editPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:create or ${permissionPrefix}${domainObjectName?uncap_first }:update" />
<c:set var="isCreate" value="${r'${model.' }${primaryKeyColumns[0].javaProperty }${r'==null}' }"/>

<!DOCTYPE html>
<html>
<head>
<title><fmt:message key="${domainObjectName?uncap_first }" /></title>
<%@ include file="/WEB-INF/jsp/inc/inc-head.jsp"%>
<%@ include file="/WEB-INF/jsp/inc/inc-css.jsp"%>
</head>
<body>
<div class="editform">
     <b><fmt:message key="index.edit.form.title"/></b>
     <div class="editinfo">
		<form method="post" class="form " id="form" >
			<#list table.allColumns as column>
				<#if primaryKeyColumns?seq_contains(column)>
			<input name="${column.javaProperty}" value="${r'${model.' }${column.javaProperty } }" type="hidden" />
				</#if>
			</#list>
			<table class="formtable"> 
				<#assign count=0>
				<#list table.allColumns as column>
					<#if !(primaryKeyColumns?seq_contains(column))>
						<#if count%2 == 0 && count != 0>
				</tr>
						</#if>
						<#if count%2 == 0>
				<tr>
						</#if>
					<th><fmt:message key="${domainObjectName?uncap_first}.${column.javaProperty }"/></th>
							<#if  column.fullyQualifiedJavaType.fullyQualifiedName?contains("Date")>
					<td><input name="${column.javaProperty }" value="<fmt:formatDate value="${r'${model.' }${column.javaProperty } }" pattern="yyyy-MM-dd"/>" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"/></td>
							<#elseif ["Integer","Short","Byte","Long"]?seq_contains(column.fullyQualifiedJavaType.shortName) >
					<td><input name="${column.javaProperty }" value="${r'${model.' }${column.javaProperty } }" class="validate[custom[number],min[0],max[9999999.99]] form-control"/></td>
							<#elseif ["Double","Float"]?seq_contains(column.fullyQualifiedJavaType.shortName) >
					<td><input name="${column.javaProperty }" value="${r'${model.' }${column.javaProperty } }" class="validate[custom[number],min[0],max[9999999]] form-control"/></td>
							<#else>
					<td><input name="${column.javaProperty }" value="${r'${model.' }${column.javaProperty } }" class="form-control"/></td>
							</#if>
						<#assign count = count + 1 >
					</#if>
				</#list>
				</tr>
			</table>
		</form>
	</div>
</div>
<div class="crud">
	<shiro:hasPermission name="${r'${editPermission}'}">
	<input type="button" onclick="save()" value="<fmt:message key="global.button.save"/>"/>
	</shiro:hasPermission>
	<input type="button" onclick="back();" value="<fmt:message key="global.button.back"/>"/>
</div>
</body>
</html>
<%@ include file="/WEB-INF/jsp/inc/inc.jsp"%>
<%@ include file="/WEB-INF/jsp/common/messager.jsp" %>
<script type="text/javascript">
function back(){
	parent.changeURL("${r'${queryURL}'}");
}
$(function(){
	$('#form').form("load",{});
	//数据校验
	$("form").validationEngine();
	<c:if test="${r'${validError}'}">
	$("form").validationEngine("validate");
	</c:if>
	<component:showFieldError commandName="model"/>
});
<shiro:hasPermission name="${r'${editPermission}'}">
$(function() { 
	<utils:if test="${r'${isCreate }' }">
	var url = '${r'${createURL }' }';
	<utils:else />
	var url = '${r'${updateURL }' }';
	</utils:if>
	$('#form').attr("action",url);
	$('#form').attr("method","post");
});
function save(){
	$('#form').submit();
}
</shiro:hasPermission>
</script>
